# make a coef plot for the polarization figure

library(ggplot2)
library(dplyr)

# this package contains some functions for making coefplots in ggplot2
if (!require(wpmarble)){
  devtools::install_github("wpmarble/wpmarble")
  library(wpmarble)
}
theme_set(theme_bw())

d = read.csv("Data/polarization_coefs.csv", stringsAsFactors = F)
d = d %>% arrange(beta)
d$depvar = factor(d$depvar, d$depvar)
ggplot(d) + 
  aes(y = depvar, x = beta, xmin = beta - 1.96 * se, xmax = beta + 1.96 * se) + 
  geom_errorbarh(height = 0) + 
  geom_point() + 
  coord_cartesian(xlim = c(0, .55)) + 
  scale_x_continuous(breaks = seq(0, 1, .1)) + 
  labs(x = "Strong Republican - Strong Democrat Difference", y = NULL) + 
  theme(panel.grid.minor = element_blank())
ggsave("Output/fig1.pdf", width=6,height=4)
ggsave("Output/fig1.eps", width=6,height=4)

# ggsave("figs/national_polarization_coefplot.pdf", width = 6, height=4)  
# ggsave("../PaperDrafts/ResearchPaper1/Graphs/national_polarization_coefplot.pdf", width=6,height=4)
